package com.yykj.hospital.server.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.client.dto.HospitalDepartmentDTO;
import com.yykj.hospital.client.dto.DepartmentListDTO;
import com.yykj.hospital.client.form.DepartmentEditForm;
import com.yykj.hospital.client.form.HotDepartmentEditForm;
import com.yykj.hospital.server.form.HospitalDepartmentSearchFrom;
import com.yykj.hospital.server.model.entity.HospitalDepartment;
import com.yykj.hospital.server.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by chendg on 2021/9/9 0009.
 */
@Slf4j
@RestController
@RequestMapping("/api/backstage/hospital/department")
@Api(tags = "科室相关接口")
@SuppressWarnings(value = "unchecked")

public class DepartmentController {

	@GetMapping("/info/{id}")
	@ApiOperation("科室信息")
	public ResultVO<HospitalDepartmentDTO> info(
			@PathVariable(name = "id", required = true) Integer id) {
		return ResultVO.success(departmentService.getDepartment(id));
	}

	@PostMapping("/add")
	@ApiOperation("创建科室")
	@ApiOperationSupport(ignoreParameters = { "id" })
	public ResultVO<HospitalDepartmentDTO> add(
			@RequestBody DepartmentEditForm departmentEditForm) {
		return ResultVO.success(departmentService.editDepartment(departmentEditForm));
	}

	@PutMapping("/edit")
	@ApiOperation("修改科室")
	@ApiOperationSupport(ignoreParameters = { "hospitalId" })
	public ResultVO<HospitalDepartmentDTO> edit(
			@RequestBody DepartmentEditForm departmentEditForm) {
		return ResultVO.success(departmentService.editDepartment(departmentEditForm));
	}

	@DeleteMapping("/delete/{id}")
	@ApiOperation("删除科室")
	public ResultVO delete(@PathVariable(value = "id", required = true) Integer id) {
		departmentService.deleteDepartment(id);
		return ResultVO.success();
	}

	@GetMapping("/list")
	@ApiOperation("搜索 -- 医院科室列表")
	public ResultVO<List<DepartmentListDTO>> getHospitalDepartment(@RequestParam(name = "hospitalId") Integer hospitalId,
																   @RequestParam(name = "depCode",required = false) String depCode,
																   @RequestParam(name = "name",required = false) String name,
																   @RequestParam(name = "level",required = false) Integer level,
																   @RequestParam(name = "sorting",required = false) Integer sorting
																   ) {

		HospitalDepartmentSearchFrom hospitalDepartmentSearchFrom = HospitalDepartmentSearchFrom.builder()
				.hospitalId(hospitalId)
				.depCode(depCode)
				.name(name)
				.level(level)
				.sorting(sorting)
				.build();
		return ResultVO.success(departmentService.getHospitalDepartment(hospitalDepartmentSearchFrom));
	}


	private DepartmentService departmentService;

	@Autowired
	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

}
